package com.dgshanger.sanhxiaofeisc.mvp.model

import com.blankj.utilcode.util.EncryptUtils
import com.dgshanger.sanhxiaofeisc.common.AppApi
import com.dgshanger.sanhxiaofeisc.mvp.contract.ForgetPwContract
import com.xx.baseutilslibrary.network.rx.RxHelper
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * ForgetPwModel
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/2/6 11:42.
 */

class ForgetPwModel : ForgetPwContract.Model {
    override fun sendVCode(phone: String, httpObserver: XxBaseHttpObserver<Any>) {
        AppApi.Api()
                .get_pin(phone, "app_forget_pwd")
                .compose(RxHelper.io_main())
                .compose(RxHelper.start_finish(httpObserver))
                .subscribe(httpObserver)
    }

    override fun changePw(phone: String, vCode: String, password: String, httpObserver: XxBaseHttpObserver<Any>) {

        AppApi.Api()
                .setPass(phone,
                        EncryptUtils.encryptMD5ToString(password).toLowerCase(),
                        EncryptUtils.encryptMD5ToString(password).toLowerCase(),
                        vCode)
                .compose(RxHelper.io_main())
                .compose(RxHelper.start_finish(httpObserver))
                .subscribe(httpObserver)
    }
}
